<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class indentController extends Controller
{   
	//后台订单列表******  待付款******************
    public function menu()
    {
    	$data = DB::table('indent as i')
    	     -> select('i.*','u.*','g.*','i.id as iid')
    	     -> leftjoin('users as u','u.id','=','i.uid')
    	     -> leftjoin('goods as g','g.id','=','i.gid')
    	     -> where('sign','0')
    	     -> where('pay','0')
    	     -> get();
        //dd($data);
        return view('admin.indent.menu',['data' => $data]);
    }
    //后台订单列表 已付款 待发货***************************
    public function payMenu()
    {
    		$data = DB::table('indent as i')
    	     -> select('i.*','u.*','g.*','i.id as iid')
    	     -> leftjoin('users as u','u.id','=','i.uid')
    	     -> leftjoin('goods as g','g.id','=','i.gid')
    	     -> where('sign','0')
    	     -> where('pass','0')
    	     -> where('pay','1')
    	     -> get();
        return view('admin.indent.menu',['data' => $data]);

    }
    //后台订单列表 已付款 已发货 待签收*****************
    public function passMenu()
    {
    	$data = DB::table('indent as i')
    	     -> select('i.*','u.*','g.*','i.id as iid')
    	     -> leftjoin('users as u','u.id','=','i.uid')
    	     -> leftjoin('goods as g','g.id','=','i.gid')
    	     -> where('sign','0')
    	     -> where('pass','1')
    	     -> where('pay','1')
    	     -> get();
        return view('admin.indent.menu',['data' => $data]);
    }
        //后台订单列表 已付款 已发货 待签收*****************
    public function overMenu()
    {
    	$data = DB::table('indent as i')
    	     -> select('i.*','u.*','g.*','i.id as iid')
    	     -> leftjoin('users as u','u.id','=','i.uid')
    	     -> leftjoin('goods as g','g.id','=','i.gid')
    	     -> where('sign','1')
    	     -> where('pass','1')
    	     -> where('pay','1')
    	     -> get();
        return view('admin.indent.menu',['data' => $data]);
    }

    //后台发货**********************
    public function pass($id)
    {    
    	date_default_timezone_set('PRC');
        $time = date("Y-m-d H:i:s");
    	$data = array('pass' => '1','ptime' => $time);
    	//dd($data);
    	$res = DB::table('indent')
    	    -> where('id',$id)
    	    -> where('pay','1')
    	    -> update($data);
    	    
    	if($res)
    	{
    		return redirect('/admin/indent/payMenu') -> with(['info' => '发货陈功']);
    	}else{
    		return back() -> with(['info' => '发货失败']);
    	}	

    }
    //取消后台发货****************************
    public function unpass($id)
    {

      $data = array('pass' => '0','ptime' => '');
      $res = DB::table('indent')
           -> where('id',$id)
           -> where('pay','1')
           -> update($data);
           //dd($data);
       if($res)
       {
     	return redirect('/admin/indent/passMenu') -> with(['info' => '取消发货陈功']);
       }else{
         return back() -> with(['info' => '取消发货失败']);
       }
    }   
    //后台签收*************************
    public function sign($id)
    {
         date_default_timezone_set('PRC');
         $time = date("Y-m-d H:i:s");
         $data = array('sign' => '1','overTime' => $time);
       $res = DB::table('indent')
           -> where('id',$id)
           -> where('pay','1')
           -> where('pass','1')
           -> update($data);
       	if($res)
    	{
    		return redirect('/admin/indent/passMenu') -> with(['info' => '签收陈功']);
    	}else{
    		return back() -> with(['info' => '签收失败']);
    	}	
    }
    //后台取消签收********************
    public function unsign($id)
    {

      $data = array('sign' => '0','overTime' => '');
      $res = DB::table('indent')
           -> where('id',$id)
           -> where('pass','1')
           -> update($data);
       if($res)
       {
     	return redirect('/admin/indent/overMenu') -> with(['info' => '取消签收陈功']);
       }else{
         return back() -> with(['info' => '取消签收失败']);
       }
    } 
}
